Puzzles from adventofcode.com 2015

Day 2: I Was Told There Would Be No Math


In [15]:
def compute_feets(text):
    l, w, h = [int(v) for v in text.split('x')]
    f1 = l*w 
    f2 = w*h 
    f3 = h*l 
    return 2*(f1 + f2 + f3) + min(f1, f2, f3)

In [8]:
# Test examples
compute_feets("1x1x10")


Out[8]:
43

In [16]:
# Real input
with open('day2/input.txt', 'rt') as gifts:
    total_feets = 0
    for gift in gifts:
        total_feets += compute_feets(gift.rstrip())
    print("They should order {} square feet of wrapping paper".format(total_feets))


They should order 1586300 square feet of wrapping paper

In [17]:
def compute_ribbon(text):
    l, w, h = [int(v) for v in text.split('x')]
    return 2*(l + w + h - max(l, w, h)) + l*w*h

In [18]:
# Test examples
compute_ribbon("2x3x4")


Out[18]:
34

In [19]:
# Real input
with open('day2/input.txt', 'rt') as gifts:
    total_ribbon = 0
    for gift in gifts:
        total_ribbon += compute_ribbon(gift.rstrip())
    print("They should order {} feet of ribbon".format(total_ribbon))


They should order 3737498 feet of ribbon